import 'package:flutter/material.dart';

class RadioPage extends StatefulWidget {
  RadioPage({Key key}) : super(key: key);

  @override
  _RadioPageState createState() => _RadioPageState();
}

class _RadioPageState extends State<RadioPage> {
  var sex = 1;
  var flag = true;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Radio页面"),
      ),
      body: Padding(
        padding: EdgeInsets.all(20),
        child: Column(
          children: <Widget>[
            Row(
              children: <Widget>[
                Text("男"),
                Radio(
                  value: 1,
                  onChanged: (selectStatus) {
                    setState(() {
                      this.sex = selectStatus;
                    });
                  },
                  groupValue: this.sex,
                ),
                SizedBox(width: 20),
                Text("女"),
                Radio(
                  value: 2,
                  onChanged: (selectStatus) {
                    setState(() {
                      this.sex = selectStatus;
                    });
                  },
                  groupValue: this.sex,
                )
              ],
            ),
            Row(
              children: <Widget>[Text(this.sex == 1 ? "男" : "女")],
            ),
            SizedBox(height: 40),
            Column(
              children: <Widget>[
                RadioListTile(
                  value: 1,
                  onChanged: (changedStatus) {
                    setState(() {
                      this.sex = changedStatus;
                    });
                  },
                  groupValue: this.sex,
                  title: Text("标题"),
                  subtitle: Text("二级标题"),
                  secondary: Icon(Icons.home),
                ),
                RadioListTile(
                  value: 2,
                  onChanged: (changedStatus) {
                    setState(() {
                      this.sex = changedStatus;
                    });
                  },
                  groupValue: this.sex,
                  title: Text("标题"),
                  subtitle: Text("二级标题"),
                  secondary: Image.network(
                      "https://www.itying.com/images/flutter/4.png"),
                ),
                SizedBox(height: 20),
                Switch(
                    value: this.flag,
                    onChanged: (changedStatus) {
                      setState(() {
                        this.flag = changedStatus;
                      });
                    }),
                Text(this.flag ? "打开" : "关闭")
              ],
            )
          ],
        ),
      ),
    );
  }
}
